# Author: Yu Bin
# Date: 2024/12/30 15:41:26
# E-mail: 853823259@qq.com
def use_exception1():
    while True:
        try:
            # 提示用户输入一个数字
            num = int(input("请输入数字:"))
            print(num)
            break
        except:
            print("输入的必须是整型数字")


def use_exception2():
    try:
        num = int(input("请输入整数： "))
        result = 8 / num
        print(result)
    except ValueError:
        print("请输入正确的整数")
    except ZeroDivisionError:
        print("除 0 错误")


def use_exception3():
    try:
        num = int(input("请输入整数： "))
        result = 8 // num
        print(result)
    except ValueError:
        print("请输入正确的整数")
    except Exception as e:
        print(e)
        print(f'出现异常：{e}')


def use_exception4():
    try:
        num = int(input("请输入整数： "))
        result = 8 / num
        print(result)
    except ValueError:
        print("请输入正确的整数")
    except ZeroDivisionError:
        print("除 0 错误")
    except Exception as result:
        print("未知错误 %s" % result)
    else:
        print("正常执行")
    finally:
        print("执行完成，但是不保证正确")



import test_module

def use_exception5():
    try:
        test_module.test()
    except Exception as e:
        print(e)
        print(e.__traceback__.tb_frame.f_globals["__file__"])  # 发生异常所在的文件
        print(e.__traceback__.tb_lineno)  # 发生异常所在的行数


if __name__ == '__main__':
    # use_exception1()
    use_exception2()
    # use_exception3()
    #use_exception4()
    #use_exception5()
